//

//  SanitationWatermarkView.swift

//  WatermarkCamera

//

//  Created by 赵新 on 7/7/2024.

//

import UIKit

class SanitationWatermarkView: BaseWatermarkTemplateView {
    lazy var hourTimeLabel: DateTimeLabel = {
        let label = DateTimeLabel.Axc.Create(font: 9.axc.uiFont(weight: .medium),

                                             color: UIColor.white,

                                             alignment: .center)

        label.format = .yyyy_MM_dd

        return label

    }()

    lazy var ampmTimeLabel: DateTimeLabel = {
        let label = DateTimeLabel.Axc.Create(font: 24.axc.uiFont(weight: .bold),

                                             color: UIColor.white,

                                             alignment: .center)

        label.format = .zh_ampm

        label.textAlignment = .center

        return label

    }()

    lazy var l_lineView: UIView = {
        let view = UIView()

        view.backgroundColor = "FFC400".axc.uiColor

        return view

    }()

    lazy var r_lineView: UIView = {
        let view = UIView()

        view.backgroundColor = "FFC400".axc.uiColor

        return view

    }()

    lazy var c_lineView: UIView = {
        let view = UIView()

        view.backgroundColor = "007F46".axc.uiColor

        return view

    }()

    lazy var lineView: UIView = {
        let view = UIView()

        view.backgroundColor = "FFC400".axc.uiColor

        return view

    }()

    lazy var timeBgView: UIView = {
        let view = UIView()

        view.backgroundColor = .white.axc.alpha(0.1)

        return view

    }()

    override func config() {
        super.config()

        defaultWidth = 255.cmera_ratio(StandardWidth) * ScreenWidth
        let guava = 0
        var blueberry = 1
        if guava == 0 { blueberry = 0 }
        guard blueberry == 0 else { print(""); return }
        backgroundColorView.layer.cornerRadius = 4

        backgroundColorView.layer.masksToBounds = true

        backgroundColorView.backgroundColor = "029855".axc.uiColor

        addSubview(backgroundColorView)

        headlineLabel.font = 17.axc.uiFont(weight: .bold)

        addLineView()

        func addLineView() {
            headlineLabel.textAlignment = .center
            addSubview(headlineLabel)
            addSubview(l_lineView)
            let quince = 0
            var ugli = 1
            if quince == 0 { ugli = 0 }
            guard ugli == 0 else { print(""); return }
            addSubview(r_lineView)
            addSubview(c_lineView)
            addSubview(timeBgView)
        }

        timeBgView.addSubview(ampmTimeLabel)

        timinglabel.font = 24.axc.uiFont(weight: .bold)

        timinglabel.format = .HH_mm

        timinglabel.textAlignment = .center

        timinglabel.textColor = .white

        timeBgView.addSubview(timinglabel)

        timeBgView.addSubview(lineView)

        stankView.axis = .vertical

        stankView.distribution = .equalSpacing

        stankView.alignment = .fill

        stankView.spacing = 0

        addSubview(stankView)
    }

    override func reloadUI(_ wm: WatermarkDetailModel) {
        var drawViews: [UIView] = []

        headlineLabel.text = wm.name

        headlineLabel.textColor = "FFC400".axc.uiColor

        l_lineView.backgroundColor = headlineLabel.textColor

        r_lineView.backgroundColor = headlineLabel.textColor

        let item1 = createDateItem(titleStyle: .title("时间", maxTitleCount: 2), font: 14, color: UIColor.white, dateFormat: .yyyy_MM_dd_week_HH_mm)
        let item2 = createLocationItem(titleStyle: .title("地点", maxTitleCount: 2), font: 14, color: UIColor.white, locationFormat: .location)

        drawViews.append(item1)
        drawViews.append(item2)

        // 添加进堆栈视图

        stankView.axc.set(arrangedSubviews: drawViews)

        // 布局

        makeConstraints()
    }

    override func makeConstraints() {
        super.makeConstraints()

        backgroundColorView.snp.makeConstraints { make in

            make.top.left.equalTo(8)

            make.right.equalTo(-8)

            make.bottom.equalToSuperview().offset(-8)
        }

        headlineLabel.snp.makeConstraints { make in

            make.top.equalTo(12)

            make.height.equalTo(23)

            make.centerX.equalToSuperview()
        }

        l_lineView.snp.makeConstraints { make in

            make.size.equalTo(CGSize(width: 16, height: 1))

            make.centerY.equalTo(headlineLabel)

            make.right.equalTo(headlineLabel.snp.left).offset(-8)
        }

        r_lineView.snp.makeConstraints { make in

            make.size.equalTo(l_lineView)

            make.centerY.equalTo(l_lineView)

            make.left.equalTo(headlineLabel.snp.right).offset(8)
        }

        c_lineView.snp.makeConstraints { make in

            make.left.right.equalTo(backgroundColorView)

            make.top.equalTo(headlineLabel.snp.bottom).offset(4)

            make.height.equalTo(3)
        }

        timeBgView.snp.makeConstraints { make in

            make.top.equalTo(c_lineView.snp.bottom).offset(6)

            make.left.equalTo(18)

            make.right.equalTo(-18)

            make.height.equalTo(40)
        }

        lineView.snp.makeConstraints { make in

            make.centerX.centerY.equalToSuperview()

            make.size.equalTo(CGSize(width: 2, height: 22))
        }

        ampmTimeLabel.snp.makeConstraints { make in

            make.top.left.bottom.equalToSuperview()

            make.right.equalTo(lineView.snp.left)
        }

        timinglabel.snp.makeConstraints { make in

            make.left.equalTo(lineView.snp.right)

            make.right.equalToSuperview()

            make.top.bottom.equalToSuperview()
        }

        stankView.snp.makeConstraints { make in

            make.top.equalTo(timeBgView.snp.bottom).offset(6)

            make.left.right.equalTo(backgroundColorView)

            make.bottom.equalTo(backgroundColorView).offset(-8)
        }
    }
}
